package com.vipheyue.bigcompany.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.vipheyue.bigcompany.R;
import com.vipheyue.bigcompany.fragment.ReNameFragment0;
import com.vipheyue.bigcompany.fragment.ReNameFragment1;
import com.vipheyue.bigcompany.fragment.ReNameFragment2;
import com.vipheyue.bigcompany.fragment.ReNameFragment3;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends SlidingFragmentActivity {
    private List<Fragment> fragmentArrayList;
    private FragmentManager fm;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initView();
        showFragmentIndex();
        initLeftMenu();
//        adsView();
    }


    private void showFragmentIndex() {
        fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.content, fragmentArrayList.get(0));
        ft.commit();
    }
    private void initView() {
        fragmentArrayList = new ArrayList<Fragment>();
        fragmentArrayList.add(new ReNameFragment0());
        fragmentArrayList.add(new ReNameFragment1());
        fragmentArrayList.add(new ReNameFragment2());
        fragmentArrayList.add(new ReNameFragment3());
    }
    private void initLeftMenu() {

        Fragment leftMenuFragment = new MenuLeftFragment();
        setBehindContentView(R.layout.left_menu_frame);
        getSupportFragmentManager().beginTransaction().replace(R.id.id_left_menu_frame, leftMenuFragment).commit();
        SlidingMenu menu = getSlidingMenu();
        menu.setMode(SlidingMenu.LEFT);
        // 设置触摸屏幕的模式
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
        menu.setShadowWidthRes(R.dimen.shadow_width);
        menu.setShadowDrawable(R.drawable.shadow);
        // 设置滑动菜单视图的宽度
        menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        // 设置渐入渐出效果的值
        menu.setFadeDegree(0.35f);
        // menu.setBehindScrollScale(1.0f);
        menu.setSecondaryShadowDrawable(R.drawable.shadow);
        //设置右边（二级）侧滑菜单
//        menu.setSecondaryMenu(R.layout.right_menu_frame);
//        Fragment rightMenuFragment = new MenuRightFragment();
//        getSupportFragmentManager().beginTransaction()
//                .replace(R.id.id_right_menu_frame, rightMenuFragment).commit();
    }

    public void showLeftMenu(View view) {
        getSlidingMenu().showMenu();
    }

    public void showRightMenu(View view) {
        getSlidingMenu().showSecondaryMenu();
    }
    @OnClick({R.id.home_radioBtn_rename0, R.id.home_radioBtn_rename1, R.id.home_radioBtn_rename2, R.id.home_radioBtn_rename3})
    public void onClick(View view) {

        FragmentTransaction ft = fm.beginTransaction();
        switch (view.getId()) {
            case R.id.home_radioBtn_rename0:
                ft.replace(R.id.content, fragmentArrayList.get(0));
                break;
            case R.id.home_radioBtn_rename1:
                ft.replace(R.id.content, fragmentArrayList.get(1));
                break;
            case R.id.home_radioBtn_rename2:
                ft.replace(R.id.content, fragmentArrayList.get(2));
                break;
            case R.id.home_radioBtn_rename3:
                ft.replace(R.id.content, fragmentArrayList.get(3));
                break;
        }
        ft.commit();
    }
}